package com.view.houseon;

import com.controller.houseon.ControlHouseON;
import com.presentacion.houseon.R;

import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.text.Html;
import android.text.method.LinkMovementMethod;
import android.text.util.Linkify;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

public class MainActivity extends Activity implements OnClickListener {
	
	Button btnL, btnD;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		
		setContentView(R.layout.activity_main);

		
		btnD= (Button)findViewById(R.id.btnDemo);
		btnL= (Button)findViewById(R.id.btnLogin);
		
		TextView txtRegistrate=(TextView)findViewById(R.id.txtRegistrate);
		txtRegistrate.setText(Html.fromHtml(getString(R.string.register)));
	    Linkify.addLinks(txtRegistrate, Linkify.ALL);
	    txtRegistrate.setMovementMethod(LinkMovementMethod.getInstance());
	    
	    TextView txtWeb=(TextView)findViewById(R.id.txtVersion);
	    txtWeb.setText(Html.fromHtml(getString(R.string.web)));
	    Linkify.addLinks(txtWeb, Linkify.ALL);
	    txtWeb.setMovementMethod(LinkMovementMethod.getInstance());
		
		btnL.setOnClickListener(this);
		btnD.setOnClickListener(this);
		
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.main, menu);
		return true;
	}

	@Override
	public void onClick(View arg0) {
		// TODO Auto-generated method stub
		
		if(arg0==btnL){
			
			Intent i= new Intent(MainActivity.this, LoginActivity.class);
			startActivity(i);
		}
		else if(arg0==btnD){
			
				
				String us= "demo";
				String ps= "123";
				
				if(!us.equals("") && !ps.equals("")){
					ControlHouseON.getInstancia().CurrentUsuario =ControlHouseON.getInstancia().validaUsuario(us,ps);
				
					if(ControlHouseON.getInstancia().CurrentUsuario!=null){
						
						// acceso a interfaz demo
						
						Toast.makeText(MainActivity.this, String.valueOf("conectando.."), Toast.LENGTH_SHORT).show();
						Intent i= new Intent(MainActivity.this, ListaCasaActivity.class);
						startActivity(i);
					
						
					}
				}
		}
	}

}
